package com.dong.pointandviewpager.sample.activity

import com.dong.pointandviewpager.sample.factory.DataFactory.newDataBeans
import com.dong.pointandviewpager.sample.factory.ListenerFactory.newChangedListener
import com.dong.pointandviewpager.sample.factory.ListenerFactory.newClickListener
import androidx.appcompat.app.AppCompatActivity
import com.dong.pointviewpager.widget.LoopViewPager
import android.os.Bundle
import android.widget.ImageView
import com.dong.pointandviewpager.R
import com.dong.pointviewpager.widget.GalleryViewPager
import com.dong.pointandviewpager.sample.factory.ListenerFactory
import com.dong.pointandviewpager.sample.model.ModelBean
import kotlinx.android.synthetic.main.activity_gallery.*
import kotlinx.android.synthetic.main.activity_looper.*

class GalleryActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_gallery)

        //设置Gallery中LoopViewPager的参数
        initLoopViewPager()
        //设置Gallery中其他参数
        initGalleryViewPager()
    }

    private fun initLoopViewPager() {
        var loopViewPager = galleryviewpager.loopViewPager as LoopViewPager<ModelBean>
        loopViewPager.run {
            beans = newDataBeans()
            setLoop(true)
            setRadius(1f)
            setImageScale(ImageView.ScaleType.FIT_XY)
            onLoopPageChangeListener = newChangedListener()
            onLoopPagerClickListener = newClickListener()
            initialise()
        }
    }

    private fun initGalleryViewPager() {
        galleryviewpager.run{
            setPageWidth(240) //设置ViewPager的宽度，适当小于GalleryViewPager的宽度
            setPageHeight(150) //设置ViewPager的高度
            setPageDistance(50f) //设置两侧页卡的缩进距离
            setPageScale(0.8.toFloat()) //设置两侧隐藏页面的缩放比例
            setPageAlpha(0.5.toFloat()) //设置两侧隐藏页面的透明度
            setPagerRotation(20f) //设置两侧页卡的倾斜角度
            initialise()
        }
    }
}